package antjbox;

import org.jbox2d.collision.AABB;
import org.jbox2d.collision.CircleDef;
import org.jbox2d.collision.PolygonDef;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.World;



import world.AntWorld;


public class AntBox {
	
	public AABB m_worldAABB;
	public World m_world;
	
	public AntWorld antWorld;


	public AntBox(AntWorld _antWorld)
	{
		antWorld = _antWorld;
		//antWorld.log.debug("ant box created.");
	}
	
	public void create_world() 
	{
		//antWorld.log.debug("going to set the aabb world.");
		m_worldAABB = new AABB();
		m_worldAABB.lowerBound = new Vec2(0.0f, 0.0f);
		m_worldAABB.upperBound = new Vec2(2400.0f, 1200.0f);
		Vec2 gravity = new Vec2(0, 0f);
		boolean doSleep = true;
		//antWorld.log.debug("aabb world set.");
		m_world = new World(m_worldAABB, gravity, doSleep);
		//antWorld.log.debug("world is set.");
		m_world.setGravity(gravity);
	}	
	
    public static BodyDef bd = new BodyDef(); 

    /**
     * @param radius : size of the element
     * @param density : weight of the element
     * @param pos : the position
     * @return the physical created body
     */
    public Body create_body(float radius, float density, Vec2 pos)
    {
    	CircleDef sd = new CircleDef();
        sd.radius = radius;        
        sd.density = density;         
        sd.friction = 0.5f;
        sd.restitution = 0.0f;
        bd.position = pos;//new Vec2(10f, 10f);
        Body myBody = m_world.createBody(bd);
        myBody.createShape(sd);
        myBody.setMassFromShapes();      
        return myBody;
        //antWorld.log.debug("body has been set");
    }
    
    
    public Body create_colony(Vec2 v)
    {
    	Vec2 size = new Vec2(10.0f, 10.0f);
    	PolygonDef sd = new PolygonDef();
        sd.setAsBox(size.x, size.y);
        sd.density = 0.0f;            
        sd.friction = 1.0f;
        bd.position = v;
        Body myBody = m_world.createBody(bd);
        myBody.createShape(sd);
        myBody.setMassFromShapes();      
        return myBody;
        //antWorld.log.debug("body has been set");
    }	    
	
}
